package cn.eyesea.cc.frame.processor.impl;

import cn.eyesea.cc.config.DomainConfig;
import cn.eyesea.cc.config.GlobalConfig;

import cn.eyesea.cc.entity.DomainInfo;
import cn.eyesea.cc.frame.base.ResultResource;
import cn.eyesea.cc.frame.context.CreateLogicalLayerCodeContext;
import cn.eyesea.cc.frame.context.CreateLogicalTypeCodeContext;
import cn.eyesea.cc.frame.enums.LogicalLayerTypeEnum;
import cn.eyesea.cc.frame.enums.LogicalTypeEnum;
import cn.eyesea.cc.frame.processor.CreateLogicalLayerCodeProcessor;
import cn.eyesea.cc.frame.processor.CreateLogicalTypeCodeProcessor;
import lombok.extern.slf4j.Slf4j;

import java.util.List;

/**
 * 默认层代码生成
 *
 * @author wanghuilong
 * @version 1.0
 * @date 2021/7/12 10:56 下午
 */
@Slf4j
public class CreateLogicalLayerCodeProcessorDefaultImpl implements CreateLogicalLayerCodeProcessor {


    CreateLogicalTypeCodeProcessor createLogicalTypeCodeProcessor;

    public CreateLogicalLayerCodeProcessorDefaultImpl(CreateLogicalTypeCodeProcessor createLogicalTypeCodeProcessor) {
        this.createLogicalTypeCodeProcessor = createLogicalTypeCodeProcessor;
    }

    @Override
    public void process(CreateLogicalLayerCodeContext createLogicalLayerCodeContext) {
        //逻辑层类型
        LogicalLayerTypeEnum logicalLayer = createLogicalLayerCodeContext.getLogicalLayer();

        //逻辑类型
        List<LogicalTypeEnum> logicalTypeList = logicalLayer.getLogicalTypeList();

        DomainInfo domainInfo = createLogicalLayerCodeContext.getDomainInfo();

        for (int i = 0; i < logicalTypeList.size(); i++) {
            CreateLogicalTypeCodeContext context = new CreateLogicalTypeCodeContext();
            context.setDomainInfo(domainInfo);
            context.setLogicalTypeEnum(logicalTypeList.get(i));
            context.setLogicalLayerTypeEnum(logicalLayer);
            context.setDomainConfig(createLogicalLayerCodeContext.getDomainConfig());
            context.setGlobalConfig(createLogicalLayerCodeContext.getGlobalConfig());
            createLogicalTypeCodeProcessor.process(context);
        }
    }


}
